package com.tadpole.music.view.widget;

import android.app.Activity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.widget.TextView;

import com.tadpole.music.R;

import razerdp.basepopup.BasePopupWindow;

/**
 * 蝌蚪云考试退出
 * Created By 孙岩
 * on 2020/10/9
 */
public class YunOutPopup extends BasePopupWindow implements View.OnClickListener {
    private TextView tvYunLoginOut;
    private IModeSelection iModeSelection;

    public YunOutPopup(Activity context) {
        super(context);
        tvYunLoginOut = (TextView) findViewById(R.id.tvYunLoginOut);
        tvYunLoginOut.setOnClickListener(this);
        getPopupWindow().setOutsideTouchable(false);
        getPopupWindow().setFocusable(false);
        getPopupWindow().setTouchable(true);

    }

    @Override
    public boolean onDispatchKeyEvent(KeyEvent event) {
        if(getPopupWindow()!=null&&getPopupWindow().isShowing()){
            return false;
        }else{
            return super.onDispatchKeyEvent(event);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onBackPressed() {
        if(getPopupWindow()!=null&&getPopupWindow().isShowing()){
            return  false;
        }else{
            return super.onBackPressed();
        }
    }

    @Override
    protected Animation initShowAnimation() {
        return null;
    }

    @Override
    public View getClickToDismissView() {
        return getPopupWindowView();
    }

    @Override
    public View onCreatePopupView() {
        return createPopupById(R.layout.pop_yun_out);
    }

    @Override
    public View initAnimaView() {
        return findViewById(R.id.rlLoginOut);
    }

    public void setModeListener(IModeSelection iModeSelection) {
        this.iModeSelection = iModeSelection;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tvYunLoginOut) {
            iModeSelection.getMode(1);
        }
    }

    public interface IModeSelection{
        void getMode(int mode);
    }
}
